package cn.fl.risk.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.service.IAudCreditInfoService;
import cn.fl.capital.condition.CapFundQueryCondition;
import cn.fl.capital.dto.CapCstPayListDTO;
import cn.fl.capital.service.ICapFundService;
import cn.fl.capital.vo.CapFundVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.customer.vo.CstBscInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.service.IMcrBillMService;
import cn.fl.mcr.vo.McrBillMVO;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.project.condition.PrjPrdPaySchMQueryCondition;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdPaySchMService;
import cn.fl.project.vo.PrjPrdPaySchDVO;
import cn.fl.project.vo.PrjPrdPaySchMVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.risk.condition.RskCommRecQueryCondition;
import cn.fl.risk.condition.RskRentRemindQueryCondition;
import cn.fl.risk.service.IRskRentRemindService;
import cn.fl.risk.vo.CapCstPayListVO;
import cn.fl.risk.vo.RskPayPrdTypRVO;
import cn.fl.risk.vo.RskRemindPayDtlVO;
import cn.fl.risk.vo.RskRentRemindVO;
import cn.fl.system.api.ISysJobApiService;
import cn.fl.system.constant.SysLogConstant;
import cn.lionbridgecapital.loan.model.condition.McrBillMQC;
import cn.lionbridgecapital.loan.model.dto.McrLoanAccountDTO;
import cn.lionbridgecapital.loan.service.api.IMcrLoanAccountApiService;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import fl.customer.facade.customer.condition.CstBscInfoQueryCondition;
import fl.pbl.facade.pbl.api.IPblBillMApiService;
import fl.pbl.facade.pbl.condition.PblBillMQC;
import fl.pbl.facade.pbl.dto.PblBillMDTO;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 租金提醒 控制层
 */
@Controller
@RequestMapping("/risk/rentRemind")
public class RskRentRemindController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(RskRentRemindController.class);

    @Autowired
    private IRskRentRemindService rskRentRemindService;
    /**
     * 客户 服务层BEAN
     */
    @Autowired
    private ICstBscInfoService cstBscInfoService;
    @Autowired
    private ICapFundService capFundService;
    @Autowired
    private IPrjPrdPaySchMService prjPrdPaySchMService;
	@Autowired
	private IAudCreditInfoService audCreditInfoService;
	@Autowired
	private IFriBaseInfoService friBaseInfoService;//融资机构基础信息表
	@Autowired
	private IPrjBscInfoService prjBscInfoService;//项目基础信息表
    @Autowired
    private IMcrBillMService mcrBillMService;
    @Autowired
    private IMcrLoanAccountApiService publicMcrLoanAccountApiService;
    @Autowired
    private IPblBillMApiService iPblBillMApiService;


    @Autowired
    private ISysJobApiService sysJobApiService ;
    /**
     * 租金提醒管理页面
     */
    @RequestMapping(value = "/toMgrPage.do", method = {RequestMethod.GET})
    public ModelAndView toMgrPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toMgrPage", "加载到租金提醒管理页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rentRemind/rentRemind");
        return mav;
    }

    /**
     * 租金提醒列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toMgrPage", "加载到租金提醒列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rentRemind/rentRemindList");

        //TODO 2017-12-12 ZT 加入货物种类
        List<KeyValueVO> searchPrdTypCdList = this.rskRentRemindService.searchPrdTypCdList();
        mav.addObject("prdTypCdList", JSON.toJSONString(searchPrdTypCdList));
        
    	//主货物大类
		List<KeyValueVO> mainGdsTypCdList = this.audCreditInfoService.searchGoodsTypListByLvl("1");
		mav.addObject("mainGdsTypCdList", mainGdsTypCdList);
		
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        mav.addObject("buOrgCdList", JSON.toJSONString(orgList));

       //查询项目类型
        List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();
    	mav.addObject("projectTypeList", projectTypeList);
        //查询第三方机构
		Pager page = new Pager();
		page.setCurrentPage(1);
		page.setEveryPage(Integer.MAX_VALUE);
		FriBaseInfoQueryCondition qc = new FriBaseInfoQueryCondition();
		qc.setInsSts(FriBaseInfoConstant.FRI_BASE_INFO_INS_STS_PASS);
		qc.setInsUseCd("2");
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(qc);
		Pager pager = this.friBaseInfoService.searchListPage(page);
		List<FriBaseInfoVO> list = (List<FriBaseInfoVO>) pager.getResultList();
		mav.addObject("friBaseList", list);	
        String currentOrgCd = CurrentThreadContext.getCurrentOrgCd();
        if(currentOrgCd.length()>8){
            if(CollectionUtils.isNotEmpty(orgList)){
                for(KeyValueVO kv:orgList){
                    if(kv.getKey().equals(currentOrgCd.substring(0, 8))){
                        mav.addObject("currOrg", CurrentThreadContext.getCurrentOrgCd());
                        break;
                    }
                }
            }
        }
        return mav;
    }

    /**
     * 初始化列表，初始化租金提醒列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initRemindList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initRemindList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        String cstNm = request.getParameter("cstNm");
        String buOrgCd = request.getParameter("buOrgCd");
        String startPayDts = request.getParameter("startPayDts");
        String endPayDts = request.getParameter("endPayDts");
        String startAppoDt = request.getParameter("startAppoDt");
        String endAppoDt = request.getParameter("endAppoDt");
        String collectWayCd = request.getParameter("collectWayCd");
        String lsCntNo = request.getParameter("lsCntNo");
        String cstMgrOrgCd = request.getParameter("cstMgrOrgCd");
        String prjTypCd = request.getParameter("prjTypCd");
        String insCode = request.getParameter("insCode");

        RskRentRemindQueryCondition qc = new RskRentRemindQueryCondition();
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        if (StringUtils.isNotBlank(startPayDts)) {
            qc.setStartPayDts(startPayDts);
        }
        if (StringUtils.isNotBlank(endPayDts)) {
            qc.setEndPayDts(endPayDts);
        }
        if (StringUtils.isNotBlank(startAppoDt)) {
            qc.setStartAppoDt(startAppoDt);
        }
        if (StringUtils.isNotBlank(endAppoDt)) {
            qc.setEndAppoDt(endAppoDt);
        }
        if (StringUtils.isNotBlank(collectWayCd)) {
            qc.setCollectWayCd(collectWayCd);
        }
        if (StringUtils.isNotBlank(lsCntNo)) {
            qc.setLsCntNo(lsCntNo);
        }
        if (StringUtils.isNotBlank(cstMgrOrgCd)) {
            qc.setCstMgrOrgCd(cstMgrOrgCd);
        }
        if (StringUtils.isNotBlank(prjTypCd)) {
            qc.setPrjTypCd(prjTypCd);
        }
        if (StringUtils.isNotBlank(insCode)) {
            qc.setInsCode(insCode);
        }
        page.setCondition(qc);

        BaseLogUtils.info(logger, "initRskCommRecList", "初始化租金提醒列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        Pager pager = this.rskRentRemindService.searchListPage(page);
        List<RskRentRemindVO> list = (List<RskRentRemindVO>) pager.getResultList();
        ListPageVO<RskRentRemindVO> listPage = new ListPageVO<RskRentRemindVO>(list, pager.getTotalCount());
        return listPage;
    }

    /**
     * 初始化列表，初始化租金提醒支付表明细列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initRemindPayList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initRemindPayList(HttpServletRequest request, HttpServletResponse response) {
        String cstId = request.getParameter("cstId");
        String cstNm = request.getParameter("cstNm");
        String buOrgCd = request.getParameter("buOrgCd");
        String startPayDts = request.getParameter("startPayDts");
        String endPayDts = request.getParameter("endPayDts");
        String startAppoDt = request.getParameter("startAppoDt");
        String endAppoDt = request.getParameter("endAppoDt");
        String prjTypCd = request.getParameter("prjTypCd");
        String insCode = request.getParameter("insCode");

        RskRentRemindQueryCondition qc = new RskRentRemindQueryCondition();
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        if (StringUtils.isNotBlank(startPayDts)) {
            qc.setStartPayDts(startPayDts);
        }
        if (StringUtils.isNotBlank(endPayDts)) {
            qc.setEndPayDts(endPayDts);
        }
        if (StringUtils.isNotBlank(startAppoDt)) {
            qc.setStartAppoDt(startAppoDt);
        }
        if (StringUtils.isNotBlank(endAppoDt)) {
            qc.setEndAppoDt(endAppoDt);
        }
        if (StringUtils.isNotEmpty(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
       if (StringUtils.isNotBlank(prjTypCd)) {
            qc.setPrjTypCd(prjTypCd);
        }
        if (StringUtils.isNotBlank(insCode)) {
            qc.setInsCode(insCode);
        }
        BaseLogUtils.info(logger, "initRskCommRecList", "初始化租金提醒支付表明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<RskRemindPayDtlVO> list = this.rskRentRemindService.searchList(qc);
        if (CollectionUtils.isNotEmpty(list)) {
            return new ListPageVO<RskRemindPayDtlVO>(list, list.size());
        }
        return null;
    }

    /**
     * 客户账单页面
     */
    @RequestMapping(value = "/toCstBillPage.do", method = {RequestMethod.GET})
    public ModelAndView toCstBillPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toCstBillPage", "客户账单查询页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rentRemind/cstBillList");
        return mav;
    }

    /**
     * 客户来款页面
     */
    @RequestMapping(value = "/toCstFundPage.do", method = {RequestMethod.GET})
    public ModelAndView toCstFundPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toCstFundPage", "客户来款查询页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rentRemind/cstFundList");
        return mav;
    }
    /**
     * 客户支付表页面
     */
    @RequestMapping(value = "/toCstPayPage.do", method = {RequestMethod.GET})
    public ModelAndView toCstPayPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toCstPayPage", "客户支付表查询页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("risk/rentRemind/cstPayList");
        return mav;
    }

    /**
     * 初始化列表，初始化客户账单明细列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initCstBillList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initCstBillList(HttpServletRequest request, HttpServletResponse response) {
        String cstNm = request.getParameter("cstNm");
        String cstId = request.getParameter("cstId");
        RskRentRemindQueryCondition qc = new RskRentRemindQueryCondition();
        if(StringUtils.isBlank(cstNm)&&StringUtils.isBlank(cstId)){
            return new ListPageVO<CapCstPayListDTO>(new ArrayList<CapCstPayListDTO>(),0);
        }

        if(StringUtils.isNotBlank(cstId)){
            qc.setCstId(Long.valueOf(cstId));
        }else{
            if (StringUtils.isNotBlank(cstNm)) {
                qc.setCstNm(cstNm);
            }
        }

        BaseLogUtils.info(logger, "initCstBillList", "初始化客户账单明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<CapCstPayListVO> list = this.rskRentRemindService.searchCstBillList(qc);
        return new ListPageVO<>(list, list.size());
    }


    /***
     * 初始化挂靠公司账单列表
     * @param request
     * @param response
     * @return
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initLnkCompCstBillList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initLnkCompCstBillList(HttpServletRequest request, HttpServletResponse response) {
        String lnkCompNm = request.getParameter("lnkCompNm");
        RskRentRemindQueryCondition qc = new RskRentRemindQueryCondition();
        if(StringUtils.isBlank(lnkCompNm)){
            return new ListPageVO<CapCstPayListDTO>(new ArrayList<CapCstPayListDTO>(),0);
        }

        qc.setLnkCompNm(lnkCompNm);


        BaseLogUtils.info(logger, "initLnkCompCstBillList", "初始化挂靠公司账单明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<CapCstPayListDTO> list = this.rskRentRemindService.searchLnkCompCstBillList(qc);
        return new ListPageVO<CapCstPayListDTO>(list, list.size());
    }

    /**
     * 初始化列表，初始化客户来款明细列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initCstFundList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initCstFundList(HttpServletRequest request, HttpServletResponse response) {
        String cstNm = request.getParameter("cstNm");
        String cstId = request.getParameter("cstId");
        CapFundQueryCondition qc = new CapFundQueryCondition();
        if(StringUtils.isBlank(cstNm)&&StringUtils.isBlank(cstId)){
            return new ListPageVO<CapFundVO>(new ArrayList<CapFundVO>(),0);
        }
        if(StringUtils.isNotBlank(cstId)){
            qc.setCstId(Long.valueOf(cstId));
        }else{
            if (StringUtils.isNotBlank(cstNm)) {
                qc.setCstNm(cstNm);
            }
        }
        if(StringUtils.isEmpty(cstId) && StringUtils.isNotEmpty(cstNm)){
        	CstBscInfoQueryCondition cstBscInfoQueryCondition = new CstBscInfoQueryCondition();
            cstBscInfoQueryCondition.setCstNm(cstNm);
            List<CstBscInfoVO> searchListByCon = cstBscInfoService.searchListByCon(cstBscInfoQueryCondition);
            BaseLogUtils.info(logger, "initCstFundList", "初始化客户来款明细列表searchListByCon.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
            if(CollectionUtils.isNotEmpty(searchListByCon)){
            	List<Long> cstIdList=new ArrayList<>();
            	for (CstBscInfoVO cstBscInfoVO : searchListByCon) {
            		cstIdList.add(cstBscInfoVO.getId());
				}
            	if(CollectionUtils.isNotEmpty(cstIdList)){
                    qc.setCstIdList(cstIdList);
            	}
            }else{
                BaseLogUtils.info(logger, "initCstFundList", "初始化客户来款明细列表searchListByCon res is null.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
                return new ListPageVO<CapFundVO>(new ArrayList<>(), 0);
            }
        }
        BaseLogUtils.info(logger, "initCstFundList", "初始化客户来款明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<CapFundVO> list = this.capFundService.searchList(qc);
        return new ListPageVO<CapFundVO>(list, list.size());
    }

    /**
     * 初始化列表，初始化客户支付表列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initPaySchList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initPaySchList(HttpServletRequest request, HttpServletResponse response) {
        String cstNm = request.getParameter("cstNm");
        String cstId = request.getParameter("cstId");
        PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
        if(StringUtils.isBlank(cstNm)&&StringUtils.isBlank(cstId)){
            return new ListPageVO<PrjPrdPaySchMVO>(new ArrayList<PrjPrdPaySchMVO>(),0);
        }

        if(StringUtils.isNotBlank(cstId)){
            qc.setCstId(Long.valueOf(cstId));
        }else{
            if (StringUtils.isNotBlank(cstNm)) {
                qc.setCstNm(cstNm);
            }
        }
        qc.setIsAllBiz(1);
        qc.setIsEnable(1);
        BaseLogUtils.info(logger, "initPaySchList", "初始化客户支付表列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<PrjPrdPaySchMVO> list = this.rskRentRemindService.searchPaySchList(qc);
        return new ListPageVO<PrjPrdPaySchMVO>(list, list.size());
    }

    /**
     * 初始化列表，初始化客户支付表明细列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initPaySchDList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initPaySchDList(HttpServletRequest request, HttpServletResponse response) {
        String paySchId = request.getParameter("paySchId");
        PrjPrdPaySchDQueryCondition qc = new PrjPrdPaySchDQueryCondition();
        if (StringUtils.isNotBlank(paySchId)) {
            qc.setPaySchId(Long.valueOf(paySchId));
        }else{
            return new ListPageVO<PrjPrdPaySchDVO>(new ArrayList<PrjPrdPaySchDVO>(),0);
        }

        BaseLogUtils.info(logger, "initPaySchDList", "初始化客户支付表明细列表.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<PrjPrdPaySchDVO> list = this.rskRentRemindService.searchPaySchDList(qc);
        return new ListPageVO<PrjPrdPaySchDVO>(list, list.size());
    }

    /**
     * 初始化列表，初始化小贷账单列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initMcrBillList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initMcrBillMList(HttpServletRequest request, HttpServletResponse response) {
        String cstNm = request.getParameter("cstNm");
        String cstId = request.getParameter("cstId");
        McrBillMQC qc = new McrBillMQC();
        //设置查询条件？
        if(StringUtils.isBlank(cstNm)&&StringUtils.isBlank(cstId)){
            return new ListPageVO<McrBillMVO>(new ArrayList<McrBillMVO>(),0);
        }
        if(StringUtils.isNotBlank(cstId)){
            qc.setCstId(Long.valueOf(cstId));
        }else{
            if (StringUtils.isNotBlank(cstNm)) {
                qc.setCstNm(cstNm);
            }
        }
        qc.setIsDel(BaseConstant.IS_YESNO_NO);
        BaseLogUtils.info(logger, "initMcrBillList", "初始化McrBillM列表页面数据.DATA:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<McrBillMVO> list = this.mcrBillMService.searchList(qc);
        if(CollectionUtils.isNotEmpty(list)){
            for(McrBillMVO vo : list){
                if(vo.getLoanAccountId()!=null){
                    McrLoanAccountDTO mcrLoanAccountDTO = this.publicMcrLoanAccountApiService.selectMcrLoanAccountDTOById(vo.getLoanAccountId());
                    vo.setAccountName(mcrLoanAccountDTO.getAccountName());
                }
            }
        }
        return  new ListPageVO<McrBillMVO>(list, list.size());
    }

    /**
     * 初始化列表，初始化垫款列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initAdvPayList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initAdvPayList(HttpServletRequest request, HttpServletResponse response) {
        String cstNm = request.getParameter("cstNm");
        String cstId = request.getParameter("cstId");
        //设置查询条件？
        if (StringUtils.isBlank(cstNm) && StringUtils.isBlank(cstId)) {
            return new ListPageVO<PblBillMDTO>(new ArrayList<PblBillMDTO>(), 0);
        }
        PblBillMQC pblBillMQC = new PblBillMQC();
        List<Long> cstIdList = new ArrayList<>();
        if (StringUtils.isNotBlank(cstId)) {
            cstIdList.add(Long.valueOf(cstId));
            pblBillMQC.setCstId(Long.valueOf(cstId));
        } else {
            if (StringUtils.isNotBlank(cstNm)) {
                pblBillMQC.setCstNm(cstNm);
            }
        }

        BaseLogUtils.info(logger, "initAdvPayList", "初始化CapAdvFund列表页面数据.DATA:" + JSONObject.toJSONString(pblBillMQC), CurrentThreadContext.getCurrentUserName());
        List<PblBillMDTO> pblBillMDTOS = iPblBillMApiService.searchPblBillMList(pblBillMQC);
        return  new ListPageVO<PblBillMDTO>(pblBillMDTOS, pblBillMDTOS.size());
    }

    /**
     * rentRemindSms()
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/toSendRentRemindSms.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object toSendRentRemindSms(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO dataResultVO = new DataResultVO(1,"toSendRentRemindSms发送提醒成功");
        try{
            this.sysJobApiService.rentRemindSms();
        }catch (Exception e){
            dataResultVO.setSuccess(0);
            dataResultVO.setInfo("toSendRentRemindSms发送失败！");
            BaseLogUtils.info(logger, "toSendRentRemindSms", "发送短信提醒失败.DATA:" , e.getMessage());
        }
        BaseLogUtils.info(logger, "toSendRentRemindSms", "发送短信提醒成功.DATA:","success");
        return dataResultVO;
    }
    
    
    /*************
     * 修改 货物类型
     *************/
    @RequestMapping(value = "/modifyPrdTypCd.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object modifyPrdTypCd(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskPayPrdTypRVO entity = new RskPayPrdTypRVO();
        try {
            String paySchId = request.getParameter("paySchId");
            String PrdTypCd = request.getParameter("value");
            
            if (StringUtils.isEmpty(paySchId)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyPrdTypCd", "修改paySchId信息,主键参数为空！.", CurrentThreadContext.getCurrentUserName());
                return result;
            }
            entity.setPaySchId(Long.valueOf(paySchId));
            
            if(StringUtils.isNotBlank(PrdTypCd)){
            	entity.setPrdTypCd(PrdTypCd);
            	entity.setIsDel(0);
            	entity.setCrtTm(DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DDHHMMSS));
            	entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            	entity.setMdfTm(DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DDHHMMSS) );
                entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            }
      
            //查询
            RskPayPrdTypRVO selectRskPayPrdTypRById = this.rskRentRemindService.selectRskPayPrdTypRById(Long.valueOf(paySchId));
            if(selectRskPayPrdTypRById==null){
            	this.rskRentRemindService.add(entity);
            }else{
                boolean success = this.rskRentRemindService.modify(entity);
                if (!success) {
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                    BaseLogUtils.info(logger, "modifyPrdTypCd", "修改modifyPrdTypCd数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                    return result;
                }
            }
            result.setData(entity.getId());
            BaseLogUtils.info(logger, "modifyPrdTypCd", "修改modifyPrdTypCd数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyPrdTypCd", "修改modifyPrdTypCd数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyPrdTypCd", "修改modifyPrdTypCd数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
    /**
     * 租金提醒批量外呼（页面触发）
     * @param request
     * @param response
     * @return
     * @throws BaseException
     */
    @RequestMapping(value = "/rentRemindOutboundList.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO rentRemindOutboundList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "外呼成功");
        String ids = request.getParameter("ids");
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "rentRemindOutboundList", "租金提醒外呼,主键参数为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        String startPayDt = request.getParameter("startPayDt");
        if(StringUtils.isEmpty(startPayDt) || !DateUtils.isDate(startPayDt, DateUtils.YYYY_MM_DD)){
        	result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("日期为空或日期格式错误");
            BaseLogUtils.info(logger, "rentRemindOutboundList", "日期为空或日期格式错误!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        if(!DateUtils.after(new Date(), DateUtils.formatStringToDate(startPayDt, DateUtils.YYYY_MM_DD)) &&
        		!DateUtils.formatDateToString(new Date(), DateUtils.YYYY_MM_DD).equals(startPayDt)){
        	result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("应收日期必须为当前日期之后");
            BaseLogUtils.info(logger, "rentRemindOutboundList", "应收日期必须为当前日期之后!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }
        RskCommRecQueryCondition condition = new RskCommRecQueryCondition();
        //客户idlist
        condition.setCstIds(idsList);
        //当前登录人id
        Long userId  = CurrentThreadContext.getCurrentUserId();
        if(StringUtils.isEmpty(userId)){
        	result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("userId 为空");
            BaseLogUtils.info(logger, "rentRemindOutboundList", "userId 为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        //当前登录人名
        String userName = CurrentThreadContext.getCurrentUserName();
        condition.setCollectUsrId(userId);
        condition.setCollectUsrNm(userName);
        condition.setPayDt(DateUtils.formatStringToDate(startPayDt, DateUtils.YYYY_MM_DD));
        try {
        	result = this.rskRentRemindService.rentRemindOutboundList(condition);
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "rentRemindOutboundList", "租金提醒批量外呼失败,Condition:" + JSON.toJSONString(condition) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "rentRemindOutboundList", "租金提醒批量外呼失败,系统错误.Condition:" + JSON.toJSONString(condition) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }
}
